	
	// 重写easyUI验证框的验证方法
	$.extend($.fn.validatebox.defaults.rules, {    
	    IdentityCodeValid: {    
	        validator: function(value, param){    
	           return identityCodeValid(value);    
	        },    
	        message: '身份证号格式错误'   
	    },
	    phoneValid: {    
	        validator: function(value, param){    
	           return phoneValid(value);    
	        },    
	        message: '手机号格式错误'   
	    },
	});  

	// base info 基本信息
	var BI = {
		// 图书信息
		reader: {
			id 	 : '#reader-dg',
			name : 'reader',
			url  : {query: 'list', save: 'save', del: 'delete', batchDel: 'bacthDel'},
			dlg	 : {titleInsert : '新添读者信息', titleUpdate: '读者信息修改', 
					insertRule: function(){
						$('#account').textbox('readonly', false);
						$('#password').textbox({required: true });
					},
					updateRule: function(){
						$('#account').textbox('readonly', true);
						$('#password').textbox({required: false }); 
					}},
			toolbar : {id: '#reader-tb'},
		},
		// 类型信息
		category: {
			id	 : '#category-dg',
			name : 'category',
			url  : {query: 'readerCategory/list', insert: 'readerCategory/insert', update: 'readerCategory/modify', del: 'readerCategory/delete'},
			dlg	 : {title : '读者类型信息', width: 600},
			toolbar : {id: '#category-tb'},
			combobox: {
				url : 'readerCategory/combobox', // 下拉框获取数据url
				c 	: {id: '#categoryId'},
				s_c : {id: '#s_categoryId'}
			}
		},
	};
	// 读者表格对象
	BI.reader.obj 	 = new easyUI.extend.TABLE(BI.reader.name, BI.reader.url);
	// 类型弹出框表格对象
	BI.category.obj  = new easyUI.extend.DLAG_TABLE(BI.category.dlg.title, BI.category.name, BI.category.url, BI.category.dlg.width);
	// 类型下拉抗对象
	BI.category.combobox.c.obj = new easyUI.extend.Combobox(BI.category.combobox.c.id, BI.category.combobox.url);
	BI.category.combobox.s_c.obj = new easyUI.extend.Combobox(BI.category.combobox.s_c.id, BI.category.combobox.url);

	// 下拉框初始化
	function comboboxInit(){
		BI.category.combobox.c.obj.init();
		BI.category.combobox.s_c.obj.init();
	}
	
	// 重新加载类型下拉框
	function categoryComboxReload(){
		BI.category.combobox.c.obj.reload();
		BI.category.combobox.s_c.obj.reload();
	}
	
	$(document).ready(function(){
			
			// 初始化
			$(BI.reader.id).datagrid({ 
		        striped: true,
		        rownumbers: true,
		        pageSize: 10,
		        idField: 'id', //这个idField必须指定为输出的id，输出的是Id就必须是Id，不能小写
		        sortName: 'id',
		        sortOrder: 'desc',
		        width: '100%', //宽度
		        height: 500, //高度
		        url: BI.reader.url.query, //请求路径
		        singleSelect: true, //单选
		        fitColumns: true, //设置为true将自动使列适应表格宽度以防止出现水平滚动。
		        pagination: true, //启用分页
		        checkOnSelect: false,
		        selectOnCheck: false,
				resizable: false,
				queryParams:{endTime:'0'},
		        columns: [
		            [
		            	{ field: 'check',title:'', width:10, checkbox:true},
		                { field: 'id', title:'编号', align:'center', width: 70, hidden: true},
		                { field: 'userInfoId', title:'用户ID', align:'center', width: 70, hidden: true},
		                { field: 'name', title:'用户名', align:'center', width: 70},
		                { field: 'account', title:'账号', align:'center', width: 100},
		                { field: 'IDCard', title:'身份证', align:'center', width: 100},
		                { field: 'borrowBooksNum', title:'借阅册数', align:'center', width: 70},
		                { field: 'borrowNum', title:'借阅次数', align:'center', width: 70},
		                { field: 'categoryId', title:'类型Id', align:'center', width: 70, hidden: true},
		                { field: 'category', title:'类型', align:'center', width: 70},
		                { field: 'balance', title:'余额', align:'center', width: 70, formatter:
							function(value, row, index){
								return "￥" + value;
							}},
							
		                { field: 'phone', title:'手机号', align:'center', width: 70, formatter:
							function(value, row, index){
								if(value == "" || value == null){
									return '<span class="editor-null" ></span>';
								}
								return value;
							}},
							
		                { field: 'birthday', title:'出生日期', align:'center', width: 70, formatter:
							function(value, row, index){
								if(value == "" || value == null){
									return '<span class="editor-null" ></span>';
								}
								return value;
							}},
							
						{ field: 'operation', title:'操作', align:'center', width: 70, formatter:
							function(value, row, index){
								return '<a class="editor-btn green" href="javaScript:void(0);" onclick="BI.reader.obj.update(BI.reader.dlg.titleUpdate, BI.reader.dlg.updateRule)">修改</a><a class="editor-btn red" href="javaScript:BI.reader.obj.del(\'您确定要注销 ' + row.name + '这个读者信息吗？\')">注销</a>';
							}},
		            ]
		        ],
		        onLoadSuccess: function(){
		        	$(BI.reader.id).datagrid('clearChecked');
		        	
		        },
		        toolbar: $(BI.reader.toolbar.id),
		    });
		   
		   // 类型表格
		   $(BI.category.id).datagrid({ 
			   
		        striped: true,
		        rownumbers: true,
		        pageSize: 10,
		        idField: 'Id', //这个idField必须指定为输出的id，输出的是Id就必须是Id，不能小写
		        sortName: 'Id',
		        sortOrder: 'desc',
		        width: '100%', //宽度
		        height: 300, //高度
		        url: BI.category.url.query, //请求路径
		        singleSelect: true, //单选
		        fitColumns: true, //设置为true将自动使列适应表格宽度以防止出现水平滚动。
		        pagination: true, //启用分页
		        columns: [
		            [
		                { field: 'id', title:'编号', align:'center', width: 100, hidden: true},
		                { field: 'name', title:'类型', align:'center', width: 70, editor: {type: 'validatebox', options: {required: true}}},
		                { field: 'borrowBooksMaxNum', title:'可借册数', align:'center', width: 70, editor: {type: 'numberbox', options: {required: true}}},
		                { field: 'borrowBooksMaxTime', title:'可借天数', align:'center', width: 70, editor: {type: 'numberbox', options: {required: true}}},
		                { field: 'renewBorrowMaxTime', title:'可续借天数', align:'center', width: 70, editor: {type: 'numberbox', options: {required: true}}},
		                { field: 'renewBorrowMaxNum', title:'可续借次数', align:'center', width: 70, editor: {type: 'numberbox', options: {required: true}}},
						{ field: 'operation', title:'操作', align:'center', width: 70, formatter:
							function(value, row, index){
								if (row.editing){
									if (value != -1){
										var s = '<a class="editor-btn green" href="javaScript:BI.category.obj.updateSave()" >保存</a>';
										var c = '<a class="editor-btn red" href="javaScript:BI.category.obj.tableCell.cancel()" >取消</a>';
										return s + c;
									} else {
										var s = '<a class="editor-btn green" href="javaScript:BI.category.obj.insertSave()" >保存</a>';
										var c = '<a class="editor-btn red" href="javaScript:BI.category.obj.insertCancel()" >取消</a>';
										return s + c;
									}
								} else {
									var m = '<a class="editor-btn green" href="javaScript:BI.category.obj.tableCell.editor()" >编辑</a>';
									var l = '<a class="editor-btn red" href="javaScript:BI.category.obj.del()" >删除</a>';
									return m + l;
								}}},
		            ]
		        ],
		        
		        onBeforeEdit:function(index,row){
    				row.editing = true;
    				easyUI.extend.TABLE_CELL.prototype.sign = true;
    				BI.category.obj.tableCell.updateActions(index);
    			},
		    			
    			onAfterEdit:function(index,row){
    				row.editing = false;
    				row.operation = 0;
    				easyUI.extend.TABLE_CELL.prototype.sign = false;
    				BI.category.obj.tableCell.updateActions(index);
    				// 重新加载类型组合框
    				categoryComboxReload();
    			},
    			
    			onCancelEdit:function(index,row){
    				row.editing = false;
    				row.operation = 0;
    				easyUI.extend.TABLE_CELL.prototype.sign = false;
    				BI.category.obj.tableCell.updateActions(index);
    			},
	               
		        toolbar: $(BI.category.toolbar.id),
		    });
			
			// 组合框初始化
			comboboxInit();
	});
	
	BI.reader.obj.endTimeReader = function(){
		$(BI.reader.id).datagrid('reload', {endTime: 1});
	};
	
